package problem991;

//991.坏了的计算器
//https://leetcode.cn/problems/broken-calculator/

class Solution {
    public int brokenCalc(int startValue, int target) {
        int ret = 0;
        while(target > startValue) {
            if(target %2 == 0) {
                target /= 2;
            }else {
                target += 1;
            }
            ret++;
        }
        if(target < startValue) ret += startValue - target;
        return ret;
    }
}

/**
    逆向转化:

    target --> startValue
    8          5
    /2 = 4
    += 1
 */